package com.gufe.controller.user.mp.quiz;

import com.gufe.result.Result;
import com.gufe.service.user.mp.quiz.CompetitionService;
import com.gufe.vo.quiz.CompetitionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/competition")
public class CompetitionController {

 @Autowired
    private CompetitionService competitionService;

    @GetMapping("/list")
    public Result<List<CompetitionVO>> getAllCompetitions() {
        return Result.success(competitionService.getAllCompetitions());
    }

    @GetMapping("/{id}")
    public Result<CompetitionVO> getCompetitionById(@PathVariable Long id) {
        CompetitionVO competition = competitionService.getCompetitionById(id);
        if (competition != null) {
            return Result.success(competition);
        } else {
            return Result.error("未找到该比赛");
        }
    }
}